package com.eling.elcms.system.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.IndexedEmbedded;

import javax.persistence.*;

/**
 * 参数
 * 
 * @author KEN
 *
 */
@Entity
@Table(name = "sm_parameter")
public class SysParameter extends BaseModel {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Column
	private String code;

	@Column
	private String name;

	@Column
	private Class<?> valueType;

	@Column
	private String value;

	/**
	 * 备注
	 */
	@Column(length = 1023)
	@Field
	private String description;

	/**
	 * 校验方式
	 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkSysParameterValidate")
	@IndexedEmbedded
	private SysParameterValidate sysParameterValidate;

	/**
	 * 设值方式
	 */
	@Enumerated(EnumType.STRING)
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private ValueSetType valueSetType;

	@Version
	private Integer version;

	@JsonSerialize(using = EnumSerializer.class)
	public static enum ValueSetType {
		Select("下拉选择"), Text("文本输入"), Number("数字"), Time("时间"), Date("日期");

		private String display;

		ValueSetType(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Class<?> getValueType() {
		return valueType;
	}

	public void setValueType(Class<?> valueType) {
		this.valueType = valueType;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public SysParameterValidate getSysParameterValidate() {
		return sysParameterValidate;
	}

	public void setSysParameterValidate(
			SysParameterValidate sysParameterValidate) {
		this.sysParameterValidate = sysParameterValidate;
	}

	public ValueSetType getValueSetType() {
		return valueSetType;
	}

	public void setValueSetType(ValueSetType valueSetType) {
		this.valueSetType = valueSetType;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
}